package com.usian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.usian.mapper.LogMapper;
import com.usian.service.ILogService;
import com.usian.shop.entity.Log;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-01-10
 */
@Slf4j
@Service
public class LogServiceImpl extends ServiceImpl<LogMapper, Log> implements ILogService {
@Autowired
private LogMapper logMapper;
    @Override
    public PageInfo findAll(Integer pageNum, Integer pageSize, Log log) {
        PageHelper.startPage(pageNum,pageSize);
        LambdaQueryWrapper<Log> qw = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(log.getType())){
            qw.eq(Log::getType,log.getType());
        }
        if (log.getStart()!=null){
           qw.ge(Log::getCreatetime,log.getStart());
     }
        if (log.getEnd()!=null){
            qw.le(Log::getCreatetime,log.getEnd());
        }
        List<Log> logs = logMapper.selectList(qw);
        return new PageInfo(logs);
    }
}
